--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit c9b78a00cefa8dbb6fd9ccad675e5ff2448791b4
Parents : e6d6ae9
Author : Ivan <ivan@quad4.io>
Signature : Invalid signer <e46112d44649266d71fe2193e00a4710>, author is <ivan@quad4.io>
Date : 2026-07-10T16:02:17-05:00
refactor(theme): move theme initialization script to a separate file for better organization and maintainability
Changes
3 files changed, 31 insertions(+), 28 deletions(-)
Diff
diff --git a/meshchatx/src/frontend/index.html b/meshchatx/src/frontend/index.html
index a662c569..639194ce 100644
--- a/meshchatx/src/frontend/index.html
+++ b/meshchatx/src/frontend/index.html
@@ -7,32 +7,7 @@
<link rel="manifest" href="/manifest.json" />
<link rel="icon" type="image/png" href="favicons/favicon-512x512.png" />
<title>Reticulum MeshChatX</title>
- <script>
- (function () {
- try {
- var theme = null;
- if (window.MeshChatXAndroid && typeof window.MeshChatXAndroid.getPreferredUiTheme === "function") {
- theme = window.MeshChatXAndroid.getPreferredUiTheme();
- }
- if (!theme) {
- try {
- theme = window.localStorage.getItem("meshchatx_ui_theme");
- } catch (e) {}
- }
- if (theme !== "light" && theme !== "dark") {
- theme = "dark";
- }
- if (theme === "dark") {
- document.documentElement.classList.add("dark");
- document.documentElement.dataset.bootTheme = "dark";
- document.documentElement.style.colorScheme = "dark";
- } else {
- document.documentElement.dataset.bootTheme = "light";
- document.documentElement.style.colorScheme = "light";
- }
- } catch (e) {}
- })();
- </script>
+ <script src="/boot-theme.js"></script>
<style>
#meshchatx-boot-splash {
box-sizing: border-box;
diff --git a/meshchatx/src/frontend/public/boot-theme.js b/meshchatx/src/frontend/public/boot-theme.js
new file mode 100644
index 00000000..7fe888ec
--- /dev/null
+++ b/meshchatx/src/frontend/public/boot-theme.js
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: 0BSD */
+(function () {
+ try {
+ var theme = null;
+ if (window.MeshChatXAndroid && typeof window.MeshChatXAndroid.getPreferredUiTheme === "function") {
+ theme = window.MeshChatXAndroid.getPreferredUiTheme();
+ }
+ if (!theme) {
+ try {
+ theme = window.localStorage.getItem("meshchatx_ui_theme");
+ } catch (e) {}
+ }
+ if (theme !== "light" && theme !== "dark") {
+ theme = "dark";
+ }
+ if (theme === "dark") {
+ document.documentElement.classList.add("dark");
+ document.documentElement.dataset.bootTheme = "dark";
+ document.documentElement.style.colorScheme = "dark";
+ } else {
+ document.documentElement.dataset.bootTheme = "light";
+ document.documentElement.style.colorScheme = "light";
+ }
+ } catch (e) {}
+})();
diff --git a/tests/frontend/BootLoadSmoothness.test.js b/tests/frontend/BootLoadSmoothness.test.js
index 1f34045d..0aabc06b 100644
--- a/tests/frontend/BootLoadSmoothness.test.js
+++ b/tests/frontend/BootLoadSmoothness.test.js
@@ -24,11 +24,14 @@ describe("boot and load smoothness", () => {
it("index.html uses canvas-colored body instead of gray-100 flash", () => {
const html = readFileSync(resolve(ROOT, "meshchatx/src/frontend/index.html"), "utf8");
+ const bootTheme = readFileSync(resolve(ROOT, "meshchatx/src/frontend/public/boot-theme.js"), "utf8");
expect(html).not.toMatch(/body class="bg-gray-100"/);
expect(html).toContain("background-color: #f8fafc");
expect(html).toContain("background-color: #09090b");
- expect(html).toContain("meshchatx_ui_theme");
- expect(html).toContain("getPreferredUiTheme");
+ expect(html).toContain('src="/boot-theme.js"');
+ expect(html).not.toMatch(/<script(?![^>]*\bsrc=)[^>]*>/);
+ expect(bootTheme).toContain("meshchatx_ui_theme");
+ expect(bootTheme).toContain("getPreferredUiTheme");
expect(html).toContain('id="meshchatx-boot-splash"');
expect(html).toContain('id="app"');
});
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────